import java.util.Iterator;
import java.util.LinkedList;

import student.Student;


public class LinkedListDemo {
	public static void main(String[] felight){
		LinkedList<Student> studentlist = new LinkedList<Student>();
		studentlist.add(new Student(10,"frodo"));
		studentlist.add(new Student(11,"neil"));
		studentlist.add(new Student(12,"Anderson"));
		System.out.println("studentListSSize:" + studentlist.size());
		Iterator iterator = studentlist.iterator();
		System.out.println("student list contain");
		while(iterator.hasNext()){
			System.out.println(iterator.next() + " ");
		}
		System.out.println("adding new students of First location");
		studentlist.addFirst(new Student(1,"morpheus"));
		System.out.println("now the Students List contains:");
		iterator = studentlist.iterator();
		while(iterator.hasNext()){
			System.out.println(iterator.next()+"");
		}
		System.out.println("no of students in the list:" + studentlist.size());
		System.out.println("adding student at the of the list");
		studentlist.addLast(new Student(16,"trinity"));
		System.out.println("now the studentList contain:");
		iterator = studentlist.iterator();
		while(iterator.hasNext()){
			System.out.println(iterator.next() +" ");
		}
		System.out.println("adding data at 2nd location:");
		studentlist.add(1,new Student(7,"smita"));
		System.out.println("now the list contain:");
		iterator = studentlist.iterator();
		while(iterator.hasNext()){
			System.out.println(iterator.next() + "");
	}
	System.out.println("now the size of studentList:" + studentlist.size());
	System.out.println("first data:\n" + studentlist.getFirst());
	System.out.println("last data:\n" + studentlist.getLast());
	System.out.println("data at 4th position:\n" + studentlist.get(3));
	Student student = studentlist.removeFirst();
	System.out.println("data removed from 1st location:\n" + student);
	System.out.println("now the list contain:");
	iterator = studentlist.iterator();
	while(iterator.hasNext())
	{
		System.out.println(iterator.next() + "");
	}
	System.out.println("now the size of studentList:" + studentlist.size());
	Student last = studentlist.removeLast();
	System.out.println("\nstudent removed from last location:" + last);
	System.out.println("now the list contain:");
	iterator = studentlist.iterator();
	while(iterator.hasNext()){
		System.out.println(iterator.next()+ "");
	}
	System.out.println("now the size of list:" + studentlist.size());
	Student second = studentlist.remove(1);
	System.out.println("data removed from 2nd location:\n" + second);
	System.out.println("\nnow the list contain:");
	iterator = studentlist.iterator();
	while (iterator.hasNext()){
		System.out.println(iterator.next() + "");
	}
	System.out.println();
	System.out.println("now the size of list:" + studentlist.size());

	studentlist.clear();
	if(studentlist.isEmpty()){
		System.out.println("linked list is empty");
	}
	else{
		System.out.println("linked list size:" + studentlist.size());
	}
	}
}
		
		
	


